//
//  FP_UserPriceInquiryInfoCell.m
//  FootPad
//
//  Created by 张浩 on 2022/2/17.
//  Copyright © 2022 胶享悦. All rights reserved.
//

#import "MM_HomeWelfareGoodsCell.h"

static const CGFloat addTitleTag = 2000;

@interface MM_HomeWelfareGoodsCell ()

@property (nonatomic, strong) UIView *baseView;

@end

@implementation MM_HomeWelfareGoodsCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        _baseView = [[UIView alloc] init];
        _baseView.backgroundColor = [ColorUtil colorWithHexadecimal:@"#ffffff"];
        [self.contentView addSubview:_baseView];
        
        [self.baseView mas_makeConstraints:^(MASConstraintMaker *make) {
           
            make.left.right.top.bottom.equalTo(self.contentView);
            make.height.equalTo(90);
        }];
        
    }
    return self;
}

- (void)setModel:(MM_HomeStockListModel *)model {
    _model = model;
                                                                                          
    NSArray *titleArr = @[!stringIsEmpty(model.sku_name)?[NSString stringWithFormat:@"%@\n%@",model.spu_name,model.sku_name]:@"",!stringIsEmpty(model.sku_id)?model.sku_id:@"",!stringIsEmpty(model.sku_code)?model.sku_code:@"",!stringIsEmpty(model.location_name)?model.location_name:@"",!stringIsEmpty(model.reference_price)?model.reference_price:@"",!stringIsEmpty(model.price_control)?model.price_control:@""];
//    NSArray *titleWArr = @[@(9),@(6),@(5),@(5)];
    CGFloat titleW = ScreenW /titleArr.count;
//    CGFloat titleX = 0;
        
    for (UIView*subView in self.baseView.subviews) {
        
        [subView removeFromSuperview];
    }
    
    for (int i=0; i<titleArr.count; i++) {
        
        UIView *titleView = [[UIView alloc] init];
        titleView.backgroundColor = [ColorUtil colorWithHexadecimal:@"#ffffff"];
        titleView.tag = addTitleTag + i;
        titleView.layer.borderColor = MM_ColorUtil(@"#eeeeee").CGColor;
        titleView.layer.borderWidth = 0.5;
        [self.baseView addSubview:titleView];
        
        [titleView mas_makeConstraints:^(MASConstraintMaker *make) {
           
            make.left.equalTo(i * titleW);
            make.top.height.equalTo(self.baseView);
            make.width.equalTo(titleW);
        }];
        
//        titleX += titleW*[titleWArr[i] integerValue];
        
        UILabel *nameLabel = [Custom_ZHTool uiLabelCreate:titleArr[i] Font:FONT(12) TextColor:[ColorUtil colorWithHexadecimal:@"#333333"]];
        nameLabel.numberOfLines = 0;
        nameLabel.textColor = [ColorUtil colorWithHexadecimal:@"#333333"];
              
        if (i == 0) {
            
              //赋值
            nameLabel.attributedText = [Custom_ZHTool createAttributedStringWithString:[NSString stringWithFormat:@"%@\n%@",model.spu_name,model.sku_name] key:model.spu_name keyFont:FONT_BOLD(12) keyColor:[ColorUtil colorWithHexadecimal:@"#333333"]];
        }
        
        [titleView addSubview:nameLabel];
        
        [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            
            if (i == 0) {
                make.left.equalTo(12);
                make.right.equalTo(-5);
            }else {
                make.centerX.equalTo(titleView);
            }
            make.centerY.equalTo(titleView);
        }];
        
        UIView *lineView_1 = [[UIView alloc] init];
        lineView_1.backgroundColor = [ColorUtil colorWithHexadecimal:@"#DDDDDD"];
        [titleView addSubview:lineView_1];
        
        [lineView_1 mas_makeConstraints:^(MASConstraintMaker *make) {

            make.right.top.equalTo(titleView);
//            make.top.equalTo(self.scrollView);
            make.width.equalTo(0.5);
            make.height.equalTo(70);
        }];

        UIView *lineView_2 = [[UIView alloc] init];
        lineView_2.backgroundColor = [ColorUtil colorWithHexadecimal:@"#DDDDDD"];
        [titleView addSubview:lineView_2];
        
        [lineView_2 mas_makeConstraints:^(MASConstraintMaker *make) {

            make.left.top.equalTo(titleView);
//            make.top.equalTo(self.scrollView);
            make.width.equalTo(titleW);
            make.height.equalTo(0.5);
        }];
    }
}

- (void)setListNewModel:(MM_HomeStockListModel *)listNewModel {
    _listNewModel = listNewModel;
    
    NSArray *titleArr = @[!stringIsEmpty(listNewModel.sku_name)?[NSString stringWithFormat:@"%@\n%@",listNewModel.spu_name,listNewModel.sku_name]:@"",!stringIsEmpty(listNewModel.sku_id)?listNewModel.sku_id:@"",!stringIsEmpty(listNewModel.location_name)?listNewModel.location_name:@"",!stringIsEmpty(listNewModel.sku_code)?listNewModel.sku_code:@"",!stringIsEmpty(listNewModel.create_time)?listNewModel.create_time:@""];
    NSArray *titleWArr = @[@(8),@(5),@(5),@(6),@(7)];
    CGFloat titleW = ScreenW /25.0;
    CGFloat titleX = 0;

    for (UIView*subView in self.baseView.subviews) {
        
        [subView removeFromSuperview];
    }
    
    for (int i=0; i<titleArr.count; i++) {
        
        UIView *titleView = [[UIView alloc] init];
        titleView.backgroundColor = [ColorUtil colorWithHexadecimal:@"#ffffff"];
        titleView.tag = addTitleTag + i;
        titleView.layer.borderColor = MM_ColorUtil(@"#eeeeee").CGColor;
        titleView.layer.borderWidth = 0.5;
        [self.baseView addSubview:titleView];
        
        [titleView mas_makeConstraints:^(MASConstraintMaker *make) {
           
            make.left.equalTo(titleX);
            make.top.height.equalTo(self.baseView);
            make.width.equalTo(titleW*[titleWArr[i] integerValue]);
        }];
        
        titleX += titleW*[titleWArr[i] integerValue];
        
        UILabel *nameLabel = [Custom_ZHTool uiLabelCreate:titleArr[i] Font:FONT(12) TextColor:[ColorUtil colorWithHexadecimal:@"#333333"]];
        nameLabel.numberOfLines = 0;
        nameLabel.textColor = [ColorUtil colorWithHexadecimal:@"#333333"];
        
        if (i == 0) {
            
              //赋值
            nameLabel.attributedText = [Custom_ZHTool createAttributedStringWithString:[NSString stringWithFormat:@"%@\n%@",listNewModel.spu_name,listNewModel.sku_name] key:listNewModel.spu_name keyFont:FONT_BOLD(12) keyColor:[ColorUtil colorWithHexadecimal:@"#333333"]];
        }
        
        [titleView addSubview:nameLabel];
        
        [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            
            if (i == 0 || i== 1 || i == 4) {
                make.left.equalTo(12);
                make.right.equalTo(-5);
            }else {
                make.centerX.equalTo(titleView);
            }
            make.centerY.equalTo(titleView);
        }];
        
        UIView *lineView_1 = [[UIView alloc] init];
        lineView_1.backgroundColor = [ColorUtil colorWithHexadecimal:@"#DDDDDD"];
        [titleView addSubview:lineView_1];
        
        [lineView_1 mas_makeConstraints:^(MASConstraintMaker *make) {

            make.right.top.equalTo(titleView);
//            make.top.equalTo(self.scrollView);
            make.width.equalTo(0.5);
            make.height.equalTo(70);
        }];

        UIView *lineView_2 = [[UIView alloc] init];
        lineView_2.backgroundColor = [ColorUtil colorWithHexadecimal:@"#DDDDDD"];
        [titleView addSubview:lineView_2];
        
        [lineView_2 mas_makeConstraints:^(MASConstraintMaker *make) {

            make.left.top.equalTo(titleView);
//            make.top.equalTo(self.scrollView);
            make.width.equalTo(titleW);
            make.height.equalTo(0.5);
        }];
    }
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
